﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUI
{
    public partial class QuanLyHop : Form
    {
        public QuanLyHop()
        {
            InitializeComponent();
        }


        private void QuanLyHop_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'qL_DATMONANDataSet.QuanLyHop' table. You can move, or remove it, as needed.
            this.quanLyHopTableAdapter.Fill(this.qL_DATMONANDataSet.QuanLyHop);
            XuLyButtom(true);

        }

        public void XuLyButtom(bool b)
        {
            this.btFirst.Enabled = btPrevious.Enabled = btNext.Enabled = btLast.Enabled = btThem.Enabled = btXoa.Enabled = btSua.Enabled = btThoat.Enabled = b;
            btLuu.Enabled = btHuy.Enabled = grThongtin.Enabled = !b;
        }

        private void btFirst_Click(object sender, EventArgs e)
        {
            this.quanLyHopBindingSource.MoveFirst();
        }

        private void btPrevious_Click(object sender, EventArgs e)
        {
            this.quanLyHopBindingSource.MovePrevious();
        }

        private void btNext_Click(object sender, EventArgs e)
        {
            this.quanLyHopBindingSource.MoveNext();
        }

        private void btLast_Click(object sender, EventArgs e)
        {
            this.quanLyHopBindingSource.MoveLast();
        }

        private void btThem_Click(object sender, EventArgs e)
        {
            XuLyButtom(false);
            iD_PhieuDatComTextBox.Focus();
            this.quanLyHopBindingSource.AddNew();
            this.tableAdapterManager.UpdateAll(this.qL_DATMONANDataSet);
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có thực sự muốn xóa?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                this.quanLyHopBindingSource.RemoveCurrent();
                this.tableAdapterManager.UpdateAll(this.qL_DATMONANDataSet);
            }
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            iD_PhieuDatComTextBox.Focus();
            XuLyButtom(false);
        }

        private void btLuu_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.quanLyHopBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.qL_DATMONANDataSet);
            XuLyButtom(true);
        }

        private void btHuy_Click(object sender, EventArgs e)
        {
            this.quanLyHopBindingSource.CancelEdit();
            XuLyButtom(true);
        }

        private void btThemhop_Click(object sender, EventArgs e)
        {
            ThongTinHop fr = new ThongTinHop();
            fr.ShowDialog();
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có thực sự muốn thoát?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                Application.Exit();
        }

    }
}
